package com.gxa.controller;

import com.gxa.common.R;
import com.gxa.mapper.shezhimapper.LoginMapper;
import com.gxa.service.shezhiservice.LoginService;
import com.gxa.service.shezhiservice.LogoutService;
import io.swagger.annotations.*;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 用户登录
 */
@RestController
@Api(value = "登录" , tags = "登录接口API")
public class LoginController {
//    @GetMapping("/selectAllCangKuForPage")
//    @ApiOperation(value = "查询所有仓库信息接口",notes = "提供页码和每页显示数",httpMethod = "get",response = R.class)
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "page",value = "当前页码数",required = true,dataType = "int",paramType = "query"),
//            @ApiImplicitParam(name = "size",value = "每页显示数",required = true,dataType = "int",paramType = "query"),
//
//    })
//    @ApiResponses({
//            @ApiResponse(code=200,message="请求成功"),
//            @ApiResponse(code=404,message="找不到页面"),
//            @ApiResponse(code=500,message="后台服务错误")
//    })
    @Autowired(required = false)
    public R r;

    @Autowired
    LoginService loginService;

    @Autowired
    LogoutService logoutService;

    @PostMapping("/login")
    @ApiOperation(value = "登录接口",notes="提供账号和密码",httpMethod = "post",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name="username",value="用户名",required = true,dataType = "String"),
            @ApiImplicitParam(name="password",value="密码",required = true,dataType = "String")
    })
        @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R login(@RequestParam String username,@RequestParam String password){
        return loginService.login(username,password);
    }
    @PostMapping("/logout")
    @ApiOperation(value = "退出登录接口",httpMethod = "post",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R logout()
    {
        return logoutService.logout();
    }
}
